package com.gxust.service.impl;

import com.gxust.conf.md5.MD5Utils;
import com.gxust.mapper.UserMapper;
import com.gxust.pojo.User;
import com.gxust.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User list(Integer userId) {
        return userMapper.list(userId);
    }

    @Override
    public void add(User user) {
        user.setPassword(MD5Utils.inputPassToFormPass(user.getPassword())); //对密码进行加密
        userMapper.register(user.getUsername(),user.getPassword(),user.getEmail(),user.getFullName(),user.getUserRole(),user.getUserImageURL());
    }

    @Override
    public User login(User user) {
        user.setPassword(MD5Utils.inputPassToFormPass(user.getPassword())); //对密码进行加密
        return userMapper.login(user.getUsername(),user.getPassword());
    }

    @Override
    public void update(User user) {
        userMapper.updateInfo(user);
    }
    }

